package com.backend.demo.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.backend.demo.dao.MenuDao;
import com.backend.demo.entities.Menu;
import com.backend.demo.page.PageBean;
import com.backend.demo.service.IMenuService;

/**
 * 菜单service Impl
 * @author Administrator
 *
 */
@Service("menuService")
public class MenuServiceImp implements IMenuService {

	@Resource(name="menuDao")
	private MenuDao menuDao;
	
	@Override
	public List<Menu> getAllMenu() {
		return menuDao.getAllMenus();
	}
	
	@Override
	public PageBean<Menu> getAllMenusByPage(){
		return menuDao.getAllMenusByPage();
	}

	@Override
	public List<Menu> getMenuByCondition(Menu menu) {
		return menuDao.getMenusByCondition(menu);
	}

	@Override
	public Menu getMenuById(long menuID) {
		return menuDao.getMenuById(menuID);
	}
	
	@Override
	public List<Menu> getParentMenus(){
		return menuDao.getParentMenus();
	}
	
	
	@Override
	public Map<Long,List<Menu>> menusMap(){
		List<Menu> menus = getAllMenu();
		List<Menu> menuList = new ArrayList<>();
		Map<Long,List<Menu>> maps = new HashMap<>();
		for (Menu menu : menus) {
			menuList = menuDao.getMenusByParentID(menu.getMenuID());
			maps.put(menu.getMenuID(), menuList);
		}
		return maps;
	}
	
	@Override
	public int addMenu(Menu menu){
		return menuDao.addMenu(menu);
	}

	@Override
	public int updateMenu(Menu menu) {
		return menuDao.updateMenu(menu);
	}

	@Override
	public int deleteMenu(long menuID) {
		return menuDao.deleteMenu(menuID);
	}

}
